-
Notifications
You must be signed in to change notification settings - Fork 407
Move LockableScore
requirement away from Router
trait
#1694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move LockableScore
requirement away from Router
trait
#1694
Conversation
I haven't updated the test suite yet, but I wanted to seek concept ACKs on my approach. I'm not 100% sure we want to parameterize |
Generally concept ack. Its kinda annoying to make |
My thinking had been we would expand the |
ah, got it. makes sense! |
431d157
to
2032f46
Compare
Used a different approach in 2032f46 -- instead of implementing |
Docs need updating -- I'll look into that in a future commit |
Codecov ReportBase: 90.92% // Head: 92.54% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1694 +/- ##
==========================================
+ Coverage 90.92% 92.54% +1.62%
==========================================
Files 85 86 +1
Lines 46268 59531 +13263
Branches 46268 59531 +13263
==========================================
+ Hits 42067 55091 +13024
- Misses 4201 4440 +239
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
7bd046a
to
90132ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM. Would like to make progress quickly here as we may end up needing to backport this for the 0.0.111 bindings.
lightning-invoice/src/payment.rs
Outdated
@@ -1860,6 +1842,8 @@ mod tests { | |||
|
|||
// Since the path is reversed, the last element in our iteration is the first | |||
// hop. | |||
let mut locked_scorer = self.scorer.lock(); | |||
let scorer = AccountForInFlightHtlcs::new(locked_scorer.deref_mut(), inflight_htlc_map.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little strange that we are testing AccountForInFlightHtlcs
this way rather through DefaultRouter
. Then again, seems doing the latter would require using the actual find_route
code, which wouldn't lend to a simple test setup. Fine with keeping this as is, but wanted to raise this in case others have any better ideas.
lightning-invoice/src/utils.rs
Outdated
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) { | ||
self.scorer.payment_path_failed(path, short_channel_id) | ||
} | ||
|
||
fn payment_path_successful(&mut self, path: &[&RouteHop]) { | ||
self.scorer.payment_path_successful(path) | ||
} | ||
|
||
fn probe_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) { | ||
self.scorer.probe_failed(path, short_channel_id) | ||
} | ||
|
||
fn probe_successful(&mut self, path: &[&RouteHop]) { | ||
self.scorer.probe_successful(path) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are never actually called since AccountForInFlightHtlcs
is only used for channel_penalty_msat
, so they can be implemented as unreachable!()
. I wonder if we should split Score
into two different traits or if we are fine with duplicating part of the interface in Router
. I guess either way, any Score
implementation used by DefaultRouter
would also need to implement this half of the trait. Not sure what would be prefered. @tnull @TheBlueMatt Any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 7d95196
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yea, I think this is fine for now, we're probably gonna end up revisinting all of it in #1668 anyway, so...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Will need a squash once other reviewers are ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, basically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM
Feel free to squash. |
df9ea09
to
82b46ed
Compare
squashed to 82b46ed without changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one nit.
//! # use secp256k1::PublicKey; | ||
//! # use std::cell::RefCell; | ||
//! # use std::ops::Deref; | ||
//! # | ||
//! # #[cfg(not(feature = "std"))] | ||
//! # use core2::io; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you could then also remove the dependency, since it's not used anymore:
diff --git lightning-invoice/Cargo.toml lightning-invoice/Cargo.toml
index cd67bcd3..852f62f4 100644
--- lightning-invoice/Cargo.toml
+++ lightning-invoice/Cargo.toml
@@ -15,7 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = ["std"]
-no-std = ["hashbrown", "lightning/no-std", "core2/alloc"]
+no-std = ["hashbrown", "lightning/no-std"]
std = ["bitcoin_hashes/std", "num-traits/std", "lightning/std", "bech32/std"]
[dependencies]
@@ -25,7 +25,6 @@ secp256k1 = { version = "0.24.0", default-features = false, features = ["recover
num-traits = { version = "0.2.8", default-features = false }
bitcoin_hashes = { version = "0.11", default-features = false }
hashbrown = { version = "0.11", optional = true }
-core2 = { version = "0.3.0", default-features = false, optional = true }
serde = { version = "1.0.118", optional = true }
[dev-dependencies]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 addressed and squashed into c353c3e
We do this to enable users to create routers that do not need a scorer. This can be useful if they are running a node the delegates pathfinding. * Move `Score` type parameterization from `InvoicePayer` and `Router` to `DefaultRouter` * Adds a new field, `scorer`, to `DefaultRouter` * Move `AccountsForInFlightHtlcs` to `DefaultRouter`, which we will use to wrap the new `scorer` field, so scoring only happens in `DefaultRouter` explicitly. * Add scoring related functions to `Router` trait that we used to call directly from `InvoicePayer`. * Instead of parameterizing `scorer` in `find_route`, we replace it with inflight_map so `InvoicePayer` can pass on information about inflight HTLCs to the router. * Introduced a new tuple struct, InFlightHtlcs, that wraps functionality for querying used liquidity.
82b46ed
to
c353c3e
Compare
Purpose
A scorer is not necessary for users who may be using a different server from their payer node for routing. This PR will allow them to implement a
Router
without it.Implementation
Score
type parameterization fromInvoicePayer
andRouter
toDefaultRouter
scorer
, toDefaultRouter
AccountsForInflightHtlcs
toDefaultRouter
, which wewill use to wrap the new
scorer
field, so scoring only happens inDefaultRouter
explicitly.Router
trait that we used to calldirectly from
InvoicePayer
.scorer
infind_route
, we replace it withinflight_map so
InvoicePayer
can pass on information about inflightHTLCs to the router.